package com.leoman.plz_p.presenter;


import com.leoman.plz_p.interfaces.MistakeSubjectView;
import com.leoman.plz_p.module.api.CourseApi;
import com.leoman.plz_p.module.bean.BaseData;
import com.leoman.plz_p.module.bean.IdsBean;
import com.leoman.plz_p.module.bean.MapData;
import com.leoman.plz_p.module.bean.MistakeSubjectBean;
import com.leoman.plz_p.subscriber.ResponseSubscriber;
import com.leoman.plz_p.utils.UserHelper;

import cn.com.corelib.api.ResponseTransformer;
import cn.com.corelib.base.BasePresenter;

public class MistakeSubjectPresenter extends BasePresenter<MistakeSubjectView> {

    private CourseApi courseApi;

    @Override
    protected void onViewAttach() {
        super.onViewAttach();
        courseApi=getApi(CourseApi.class);
    }

    public void getMistakeSubject(){
        courseApi.getMistakeSubject(UserHelper.getToken()).compose(new ResponseTransformer<>(this.<BaseData<MapData<MistakeSubjectBean>>>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<BaseData<MapData<MistakeSubjectBean>>>(view) {
                    @Override
                    public void success(BaseData<MapData<MistakeSubjectBean>> data) {
                        view.obtainMistakeList(data.data.total,data.data.list);
                    }
                });
    }

    public void getAllMistake(){
        courseApi.getAllMistake(UserHelper.getToken()).compose(new ResponseTransformer<>(this.<BaseData<IdsBean>>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<BaseData<IdsBean>>(view) {
                    @Override
                    public void success(BaseData<IdsBean> data) {
                        if (checkDataNotNull(data))
//                        if (checkListNotNull(data.data)) {
//                            List<String> ids=new ArrayList<>();
//                            for (int i = 0; i <data.data.size() ; i++) {
//                                ids.add(data.data.get(i).ids);
//                            }
                            view.obtainAllMistake(data.data.ids);
//                        }
                    }
                });
    }

    @Override
    public void onStart() {
        getMistakeSubject();
    }
}